/*------------------------------------------------------
                hou_elearningGEN beta v1.0
Author: xtrung.net@gmail.com
Write On: 04/27/2008
Create On:4/13/2012 11:22:56 AM
------------------------------------------------------*/
using hou_elearning.DataAccess.Base;
using hou_elearning.Entity;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections.Generic;
using System.Collections;
using System.Web;

namespace hou_elearning.DataAccess
{    
    public class TacvuDAL : SqlProvider<TacvuEntity>
    {
        static TacvuDAL()
        {
            InitReader();
        }
        protected static void InitReader()
        {
            getFromReader=delegate(SqlDataReader dr)
            {
                TacvuEntity entity = new TacvuEntity();
				entity.PK_iTacvuID = Int32.Parse("0"+dr["PK_iTacvuID"].ToString());
				entity.sTentacvu = dr["sTentacvu"].ToString();
				entity.sKyhieu = dr["sKyhieu"].ToString();
				entity.sGhichu = dr["sGhichu"].ToString();
                return entity;
            };
        }
        public static TacvuEntity GetOne(Int32 PK_iTacvuID)
        {
            string cmdName = "spTacvu_GetByPK";
            SqlParameter p = new SqlParameter("@PK_iTacvuID", PK_iTacvuID);
            TacvuEntity entity = GetOne(cmdName, p);
            return entity;
        }
        public static List<TacvuEntity> GetAll()
        {
            string cmdName = "spTacvu_Get";
            return GetList(cmdName);
        }
        
        public static int Add(TacvuEntity entity)
        {
            string cmdName = "spTacvu_Insert";
            return Run(cmdName,true,initParams(entity));

        }
        public static bool Edit(TacvuEntity entity)
        {
            string cmdName = "spTacvu_Update";
            return Run(cmdName,false,initParams(entity))>0;
        }
        public static bool Remove(Int32 PK_iTacvuID)
        {
            string cmdName = "spTacvu_Delete";
            SqlParameter p = new SqlParameter("@PK_iTacvuID", PK_iTacvuID);
            return Run(cmdName,false,p)>0;
        }
        #region private
        private static SqlParameter[] initParams(TacvuEntity entity)
        {
            SqlParameter[] p = new SqlParameter[4];
			p[0] = new SqlParameter("@PK_iTacvuID", entity.PK_iTacvuID);
			p[1] = new SqlParameter("@sTentacvu", entity.sTentacvu);
			p[2] = new SqlParameter("@sKyhieu", entity.sKyhieu);
			p[3] = new SqlParameter("@sGhichu", entity.sGhichu);
            return p;
        }
        #endregion
       
    }
}